#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include "canthread.h"
#include "qcustomplot.h"
#include "rechargethread.h"
#include <QThread>

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

    QThread  *thread_1 = NULL;
    RechargeThread *recharge = NULL;

    void InitView();
    void LightInit();
    void timerEvent(QTimerEvent *event);
    void createIndicatorLabel(QLabel* label, int color, int size, QString number, bool numlock);

    void customPlotModule_V_A();

    void SignalCAN_start();
    void SignalCAN_stop();
    void SignalCAN_receive();

    void Setmodule();

    //访问模块状态
    void Visitstate1();
    void Visitstate2();
    void Visitstate3();
    void Visitstate4();

    //访问模块电压
    void VisitV1();
    void VisitV2();
    void VisitV3();
    void VisitV4();

    //访问模块电流
    void VisitA1();
    void VisitA2();
    void VisitA3();
    void VisitA4();

    //访问模块温度
    void VisitTem1();
    void VisitTem2();
    void VisitTem3();
    void VisitTem4();

    //访问模块限流点
    void VisitLimit1();
    void VisitLimit2();
    void VisitLimit3();
    void VisitLimit4();

    //访问模块工作模式
    void Visitmol1();
    void Visitmol2();
    void Visitmol3();
    void Visitmol4();

    //访问模块额定输出功率
    void VisitW1();
    void VisitW2();
    void VisitW3();
    void VisitW4();

    //电压显示
    void modView_V1(QString da);
    void modView_V2(QString da);
    void modView_V3(QString da);
    void modView_V4(QString da);

    //电流显示
    void modView_A1(QString da);
    void modView_A2(QString da);
    void modView_A3(QString da);
    void modView_A4(QString da);

    //工作模式显示
    void modView_mod1(QString da);
    void modView_mod2(QString da);
    void modView_mod3(QString da);
    void modView_mod4(QString da);

    //限流显示
    void modView_lim1(QString da);
    void modView_lim2(QString da);
    void modView_lim3(QString da);
    void modView_lim4(QString da);

    //温度显示
    void modView_tem1(QString da);
    void modView_tem2(QString da);
    void modView_tem3(QString da);
    void modView_tem4(QString da);

    //状态显示
    void modView_state1(QString da);
    void modView_state2(QString da);
    void modView_state3(QString da);
    void modView_state4(QString da);

    //额定功率显示
    void modView_w1(QString da);
    void modView_w2(QString da);
    void modView_w3(QString da);
    void modView_w4(QString da);

    //故障显示
    void BugView_SCI(int bug);
    void BugView_JX(int bug);
    void BugView_ModBug(int bug);
    void BugView_DCGY(int bug);
    void BugView_PFC(int bug);
    void BugView_JLGY(int bug);
    void BugView_JLQY(int bug);
    void BugView_CAN(int bug);
    void BugView_BJL(int bug);
    void BugView_FS(int bug);
    void BugView_DCDL(int bug);
    void BugView_DCGW(int bug);
    void BugView_DCSCGY(int bug);

    float V1 = 0;
    float V2 = 0;
    float V3 = 0;
    float V4 = 0;

    float A1 = 0;
    float A2 = 0;
    float A3 = 0;
    float A4 = 0;

    float W1 = 0;
    float W2 = 0;
    float W3 = 0;
    float W4 = 0;

    float lim1 = 0;
    float lim2 = 0;
    float lim3 = 0;
    float lim4 = 0;

    float tem1 = 0;
    float tem2 = 0;
    float tem3 = 0;
    float tem4 = 0;

    int bug1_SCI = 0;
    int bug2_SCI = 0;
    int bug3_SCI = 0;
    int bug4_SCI = 0;
    int bug1_JX = 0;
    int bug2_JX = 0;
    int bug3_JX = 0;
    int bug4_JX = 0;
    int bug1_ModBug = 0;
    int bug2_ModBug = 0;
    int bug3_ModBug = 0;
    int bug4_ModBug = 0;
    int bug1_DCGY = 0;
    int bug2_DCGY = 0;
    int bug3_DCGY = 0;
    int bug4_DCGY = 0;
    int bug1_PFC = 0;
    int bug2_PFC = 0;
    int bug3_PFC = 0;
    int bug4_PFC = 0;
    int bug1_JLGY = 0;
    int bug2_JLGY = 0;
    int bug3_JLGY = 0;
    int bug4_JLGY = 0;
    int bug1_JLQY = 0;
    int bug2_JLQY = 0;
    int bug3_JLQY = 0;
    int bug4_JLQY = 0;
    int bug1_CAN = 0;
    int bug2_CAN = 0;
    int bug3_CAN = 0;
    int bug4_CAN = 0;
    int bug1_BJL = 0;
    int bug2_BJL = 0;
    int bug3_BJL = 0;
    int bug4_BJL = 0;
    int bug1_FS = 0;
    int bug2_FS = 0;
    int bug3_FS = 0;
    int bug4_FS = 0;
    int bug1_DCDL = 0;
    int bug2_DCDL = 0;
    int bug3_DCDL = 0;
    int bug4_DCDL = 0;
    int bug1_DCGW = 0;
    int bug2_DCGW = 0;
    int bug3_DCGW = 0;
    int bug4_DCGW = 0;
    int bug1_DCSCGY = 0;
    int bug2_DCSCGY = 0;
    int bug3_DCSCGY = 0;
    int bug4_DCSCGY = 0;

private slots:
    void on_btnCan_clicked();

    void on_btn_start_clicked();

    void on_btn_stop_clicked();

    void on_btn_setV_clicked();

    void on_btn_setA_clicked();

    //游标函数
    void mouseMoveEvent(QMouseEvent *event);

    //图例选中曲线函数
    void selectionChanged();



    void on_comboBox_all_currentIndexChanged(int index);

    void on_btnCAN_clicked();

    void on_btn_res_4_clicked();

    void on_btn_res_clicked();

    void on_btn_start_2_clicked();

    void on_btn_stop_2_clicked();

    void on_btn_res_2_clicked();

    void on_btn_res_3_clicked();

    void on_btn_setV_2_clicked();

    void on_btn_setA_2_clicked();

signals:
    void SIGtocansen(unsigned int ID, std::vector<int> vec);
    void SIGtocancon();                                     //启动CAN按钮发出的信号
    void SIGtocansto();                                     //关闭CAN按钮发出的信号

    void Bug_SCI(int bug);
    void Bug_JX(int bug);
    void Bug_ModBug(int bug);
    void Bug_DCGY(int bug);
    void Bug_PFC(int bug);
    void Bug_JLGY(int bug);
    void Bug_JLQY(int bug);
    void Bug_CAN(int bug);
    void Bug_BJL(int bug);
    void Bug_FS(int bug);
    void Bug_DCDL(int bug);
    void Bug_DCGW(int bug);
    void Bug_DCSCGY(int bug);

private:
    Ui::MainWindow *ui;

    QTimer timer1;
    int refreshTimer = 0; //刷新图像的定时器
    int sampleTimer = 0; //模拟采样的定时器

    QCustomPlot *plot = NULL;
    QCPItemTracer *tracer = NULL;  //游标定义
};
#endif // MAINWINDOW_H
